package com.example.littleSpider.myapplication.activity;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.littleSpider.myapplication.R;
import com.example.littleSpider.myapplication.adapter.MallAdapter;
import com.example.littleSpider.myapplication.adapter.SpaceItemDecoration;
import com.example.littleSpider.myapplication.base.BaseActivity;
import com.example.littleSpider.myapplication.myInterfaces.MethodInTitle;
import com.example.littleSpider.myapplication.view.TitleView;
import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 市集特卖界面
 * Created by littleSpider on 2017/12/20.
 */

public class MallsActivity extends BaseActivity implements MethodInTitle{

    @BindView(R.id.title_view)
    TitleView mTitleView;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.refresh_view)
    TwinklingRefreshLayout refreshView;

    private MallAdapter mallAdapter;
    List<String> datas = new ArrayList<>();

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_mall;
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        String title = intent.getStringExtra("title");
        mTitleView.initMyTitle(title, this, false);
        mTitleView.hideTitleTextImage();
        for (int i = 0; i < 5; i++) {
            datas.add("");
        }
        refreshView.setOnRefreshListener(new RefreshAndLoad());
        mallAdapter = new MallAdapter(R.layout.item_mall_goods, datas);
        recyclerView.setAdapter(mallAdapter);
        recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        recyclerView.addItemDecoration(new SpaceItemDecoration(15));
    }

    @Override
    protected void initData() {

    }

    @Override
    public void setGoBack() {
        finish();
    }

    @Override
    public void onRightOne() {

    }

    @Override
    public void onRightTwo() {

    }

    @Override
    public void onTitleText() {

    }

    private class RefreshAndLoad extends RefreshListenerAdapter{

        @Override
        public void onRefresh(TwinklingRefreshLayout refreshLayout) {
            super.onRefresh(refreshLayout);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    refreshView.finishRefreshing();
                }
            }, 1000);
        }

        @Override
        public void onLoadMore(TwinklingRefreshLayout refreshLayout) {
            super.onLoadMore(refreshLayout);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    refreshView.finishLoadmore();
                }
            }, 1000);
        }
    }
}
